package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.UserCouponsService;
import com.junzhiit.nengji.cms.web.vo.CouponsVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.UserCouponsAddVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/all/coupons")
public class UserCouponsController extends BaseController {
	
	@Autowired
	private UserCouponsService userCouponsService;
	
	@ApiOperation("查询所有商户优惠卷")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,CouponsVO couponsVO) {
		return userCouponsService.getCouponsAll(dtp,couponsVO);
	}
	
	@ApiOperation("添加用户优惠券")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public ResultVO findById(UserCouponsAddVO userCouponsAddVO) {
		AssertUtil.notBlank(userCouponsAddVO.getUserId(), "userId is required.");
		AssertUtil.notBlank(userCouponsAddVO.getCouponsId(), "couponsId is required.");
		return userCouponsService.addCoupons(userCouponsAddVO);
	}
	
	@ApiOperation("删除用户优惠券")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delById(String couponsId) {
		AssertUtil.notBlank(couponsId, "couponsId is required.");
		return userCouponsService.delCoupons(couponsId);
	}
}
